package org.dftproject.genesis.ui.editors;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPersistableElement;

public class BrowserEditorInput implements IEditorInput {
	
	private String uri;
	
	public BrowserEditorInput(String url) {
		this.uri = url;
	}
	
	public void setUri(String url) {
		this.uri = url;
	}
	
	public String getUri() {
		return uri;
	}

	public boolean exists() {
		return true;
	}

	public ImageDescriptor getImageDescriptor() {
		return ImageDescriptor.getMissingImageDescriptor();
	}

	public String getName() {
		return uri;
	}

	public IPersistableElement getPersistable() {
		return new IPersistableElement() {

			public String getFactoryId() {
				return BrowserEditorInputFactory.ID;
			}

			public void saveState(IMemento memento) {
				memento.putString("uri", uri);
			}
			
		};
	}

	public String getToolTipText() {
		return uri;
	}

	@SuppressWarnings("unchecked")
	public Object getAdapter(Class adapter) {
		return null;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((uri == null) ? 0 : uri.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final BrowserEditorInput other = (BrowserEditorInput) obj;
		if (uri == null) {
			if (other.uri != null)
				return false;
		} else if (!uri.equals(other.uri))
			return false;
		return true;
	}

}
